home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / program / renamedata.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  5KB  |  192 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "DOpus.h"
  32.  
  33. enum {
  34.     RENAME_CANCEL,
  35.     RENAME_OKAY,
  36.     RENAME_SKIP,
  37.     RENAME_OLDNAME,
  38.     RENAME_NEWNAME};
  39.  
  40. struct RequesterBase rename_req={
  41.     40,5,24,30,
  42.     8,6,
  43.     0,0,0,0,NULL,NULL,NULL,NULL,
  44.     NULL,NULL,NULL,
  45.     0,0,NULL,0,NULL};
  46.  
  47. char oldname_buffer[40],newname_buffer[40];
  48.  
  49. struct TagItem
  50.     rename_oldname_gadget[]={
  51.         {RO_Type,OBJECT_GADGET},
  52.         {RO_GadgetType,GADGET_STRING},
  53.         {RO_GadgetID,RENAME_OLDNAME},
  54.         {RO_LeftFine,4},
  55.         {RO_Top,1},
  56.         {RO_TopFine,2},
  57.         {RO_Width,40},
  58.         {RO_Height,1},
  59.         {RO_TextNum,STR_RENAME},
  60.         {RO_TextPos,TEXTPOS_ABOVE},
  61.         {RO_StringBuf,(ULONG)oldname_buffer},
  62.         {RO_StringLen,32},
  63.         {RO_StringUndo,(ULONG)str_undobuffer},
  64.         {TAG_END,0}},
  65.     rename_newname_gadget[]={
  66.         {RO_Type,OBJECT_GADGET},
  67.         {RO_GadgetType,GADGET_STRING},
  68.         {RO_GadgetID,RENAME_NEWNAME},
  69.         {RO_LeftFine,4},
  70.         {RO_Top,3},
  71.         {RO_TopFine,8},
  72.         {RO_Width,40},
  73.         {RO_Height,1},
  74.         {RO_TextNum,STR_AS},
  75.         {RO_TextPos,TEXTPOS_ABOVE},
  76.         {RO_StringBuf,(ULONG)newname_buffer},
  77.         {RO_StringLen,32},
  78.         {RO_StringUndo,(ULONG)str_undobuffer},
  79.         {TAG_END,0}},
  80.     rename_okay_gadget[]={
  81.         {RO_Type,OBJECT_GADGET},
  82.         {RO_GadgetType,GADGET_BOOLEAN},
  83.         {RO_GadgetID,RENAME_OKAY},
  84.         {RO_Top,4},
  85.         {RO_TopFine,16},
  86.         {RO_Width,12},
  87.         {RO_Height,1},
  88.         {RO_HeightFine,4},
  89.         {RO_TextNum,STR_OKAY},
  90.         {RO_TextPos,TEXTPOS_CENTER},
  91.         {RO_HighRecess,TRUE},
  92.         {TAG_END,0}},
  93.     rename_skip_gadget[]={
  94.         {RO_Type,OBJECT_GADGET},
  95.         {RO_GadgetType,GADGET_BOOLEAN},
  96.         {RO_GadgetID,RENAME_SKIP},
  97.         {RO_Top,4},
  98.         {RO_TopFine,16},
  99.         {RO_Width,12},
  100.         {RO_Height,1},
  101.         {RO_HeightFine,4},
  102.         {RO_Left,14},
  103.         {RO_LeftFine,4},
  104.         {RO_TextNum,STR_SKIP},
  105.         {RO_TextPos,TEXTPOS_CENTER},
  106.         {RO_HighRecess,TRUE},
  107.         {TAG_END,0}},
  108.     rename_cancel_gadget[]={
  109.         {RO_Type,OBJECT_GADGET},
  110.         {RO_GadgetType,GADGET_BOOLEAN},
  111.         {RO_GadgetID,RENAME_CANCEL},
  112.         {RO_Top,4},
  113.         {RO_TopFine,16},
  114.         {RO_Width,12},
  115.         {RO_Height,1},
  116.         {RO_HeightFine,4},
  117.         {RO_Left,28},
  118.         {RO_LeftFine,8},
  119.         {RO_TextNum,STR_CANCEL},
  120.         {RO_TextPos,TEXTPOS_CENTER},
  121.         {RO_HighRecess,TRUE},
  122.         {TAG_END,0}},
  123.  
  124.     *rename_gadgets[]={
  125.         rename_oldname_gadget,
  126.         rename_newname_gadget,
  127.         rename_okay_gadget,
  128.         rename_skip_gadget,
  129.         rename_cancel_gadget,
  130.         NULL};
  131.  
  132. getrenamedata(src,dst)
  133. char *src,*dst;
  134. {
  135.     ULONG class;
  136.     USHORT code,gadgetid,qual;
  137.     struct Window *rwindow;
  138.     struct Gadget *gadlist;
  139.  
  140.     fix_requester(&rename_req,globstring[STR_ENTER_NEW_NAME]);
  141.  
  142.     strcpy(oldname_buffer,src); strcpy(newname_buffer,dst);
  143.  
  144.     if (!(rwindow=OpenRequester(&rename_req)) ||
  145.         !(gadlist=addreqgadgets(&rename_req,rename_gadgets,0,NULL))) {
  146.         CloseRequester(&rename_req);
  147.         return(0);
  148.     }
  149.     RefreshRequesterObject(&rename_req,NULL);
  150.  
  151.     Delay(3);
  152.     ActivateStrGad(gadlist->NextGadget,rwindow);
  153.  
  154.     FOREVER {
  155.         while (IMsg=(struct IntuiMessage *)GetMsg(rwindow->UserPort)) {
  156.             class=IMsg->Class; code=IMsg->Code; qual=IMsg->Qualifier;
  157.             if (class==IDCMP_GADGETUP)
  158.                 gadgetid=((struct Gadget *) IMsg->IAddress)->GadgetID;
  159.             ReplyMsg((struct Message *) IMsg);
  160.  
  161.             switch (class) {
  162.                 case IDCMP_MOUSEBUTTONS:
  163.                     gadgetid=RENAME_OLDNAME;
  164.  
  165.                 case IDCMP_GADGETUP:
  166.                     switch (gadgetid) {
  167.                         case RENAME_OLDNAME:
  168.                             ActivateStrGad(gadlist->NextGadget,rwindow);
  169.                             break;
  170.                         case RENAME_NEWNAME:
  171.                             if (qual&IEQUALIFIER_ANYSHIFT) {
  172.                                 ActivateStrGad(gadlist,rwindow);
  173.                                 break;
  174.                             }
  175.                             else if (code==0x9) break;
  176.                             gadgetid=RENAME_OKAY;
  177.  
  178.                         case RENAME_OKAY:
  179.                             strcpy(src,oldname_buffer);
  180.                             strcpy(dst,newname_buffer);
  181.                         case RENAME_SKIP:
  182.                         case RENAME_CANCEL:
  183.                             CloseRequester(&rename_req);
  184.                             return((int)gadgetid);
  185.                     }
  186.                     break;
  187.             }
  188.         }
  189.         Wait(1<<rwindow->UserPort->mp_SigBit);
  190.     }
  191. }
  192.